package Random._398_RandomPickIndex;

import java.util.*;

public class Solution {
    Map<Integer, List<Integer>> maps;
    public Solution(int[] nums) {
        this.maps = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (!maps.containsKey(nums[i])) {
                maps.put(nums[i], new ArrayList<>());
            }
                maps.get(nums[i]).add(i);
        }
    }

    public int pick(int target) {
        Random r = new Random();
        List<Integer> lists = maps.get(target);
        System.out.println(lists.toString());
        int val = r.nextInt(lists.size());
        return lists.get(val);
    }
}
